clear all

cd "~\Data"
use "study1_cors.dta"
gen study=1
append using "study2_cors.dta"
recode study .=2
append using "study3_cors.dta"
recode study .=3
append using "study4_cors.dta"
recode study .=4

tab study, gen(study)

recode var_* (.=0)

gen varpopstr="Populism" if var_pop==1
gen varantistr="Anti-Dem" if var_anti==1
gen varconspstr="Conspiracy" if var_consp==1
gen varhsstr="Sexism" if var_hs==1
gen varrrstr="Racism" if var_rr==1
gen varviolstr="Violence" if var_viol==1
gen varchaosstr="Chaos" if var_chaos==1

egen varcombstr=concat(varhsstr varpopstr varrrstr varconspstr varviolstr varchaosstr varantistr), punct(" ")
replace varcombstr=stritrim(varcombstr)

encode varcombstr, gen(varpair)
tab varpair, gen(varpair_dummy)

*do aligned and unaligned cors share sign?
gen signmatch=cor1*cor2
recode signmatch -1/-.00001=0 0/1=1
tab signmatch

*figure 1
twoway scatter cor1 cor2 if study==1, ylab(-.2(.2).8, nogrid) xlab(-.2(.2).8, nogrid) aspect(1) ytitle("Aligned Correlation") xtitle("Unaligned Correlation") mcol(reddish) || function y=x, range(-.2 .8) lcol(gs10) || lowess cor1 cor2 || scatter cor1 cor2 if study==2, mcol(sky) || scatter cor1 cor2 if study==3, mcol(orangebrown) || scatter cor1 cor2 if study==4, mcol(turquoise) legend(order(1 "Study 1 (Student)" 4 "Study 2 (Dynata)" 5 "Study 3 (MTurk)" 6 "Study 4 (Bovitz)")) yline(0) xline(0) 

*average difference
metareg diff, wsse(se) 

*sample effects
metareg diff study1 study2 study3, wsse(se) 
est store m1

*samples and variables
metareg diff var_pop var_consp var_hs var_chaos var_viol var_anti study1 study2 study3, wsse(se) 
est store v4
coefplot v4, xline(0) coeflabel(var_pop="Populism" var_consp="Conspiracy" var_hs="Hostile Sexism" var_chaos="Need for Chaos" var_viol="Violence" var_anti="Anti-Democratic" study1="Study 1 (Student)" study2="Study 2 (Dynata)" study3="Study 3 (MTurk)" study4="Study 4 (Bovitz)" _cons="Constant") order(var_pop var_hs var_viol var_anti var_consp var_chaos) subtitle("Predictors of the Magnitude of Bias") saving(metareg_coefs.gph, replace)

*combinations of variables and samples
metareg diff var_pop var_consp var_hs var_chaos var_viol var_anti study1 study2 study3, wsse(se) 
lincomest _cons+var_pop
est store p1

metareg diff var_pop var_consp var_hs var_chaos var_viol var_anti study1 study2 study3, wsse(se) 
lincomest _cons+var_chaos+var_consp
est store p2

metareg diff var_pop var_consp var_hs var_chaos var_viol var_anti study1 study2 study3, wsse(se) 
lincomest _cons+var_pop+study2
est store p3

metareg diff var_pop var_consp var_hs var_chaos var_viol var_anti study1 study2 study3, wsse(se) 
lincomest _cons+var_chaos+var_consp+study2
est store p4

coefplot p1 p2 p3 p4, asequation swapnames ylab(1 `""Populism + Racial R." "Study 4""' 2 `""Chaos + Conspiracy" "Study 4""' 3 `""Populism + Racial R." "Study 2""' 4 `""Chaos + Conspiracy" "Study 2"') legend(off) mcol(black) ciopts(col(black)) msymbol(O) subtitle("Predicted Size of Bias by Construct and Sample") saving(metareg_pvs.gph, replace)

*figure 2
graph combine metareg_coefs.gph metareg_pvs.gph


*alt analysis using variable pairs
metareg diff varpair_dummy1-varpair_dummy12 varpair_dummy14-varpair_dummy21 study1 study2 study3, wsse(se) 
est store pairs
coefplot pairs, xline(0) sort(1) keep(varpair*) ylab(, valuelabels labsize(tiny))


